class TitleMap extends egret.Sprite {
    private _lookX: number = 0;
    private _lookY: number = 0;
    private _titles: Array<egret.Bitmap> = new Array<egret.Bitmap>(16);
    private _titleWidth: number = 0;
    private _titleHeight: number = 0;

    constructor() {
        super()
    }

    public initMap(): void {
        for (let i = 0; i < this._titles.length; i++) {
            this._titles[i] = new egret.Bitmap()
            this._titles[i].texture = RES.getRes("bg_png")
            /*
            this._titles[i].filters = [new egret.ColorMatrixFilter([
                1 / (i + 1), 0.6, 0, 0, 0,
                0.3, 0.6, 0, 0, 0,
                0.3, 1 / (i + 1), 0, 0, 0,
                0, 0, 0, 1, 0
            ])]
            */
            this._titles[i].anchorOffsetX = this._titles[i].width / 2
            this._titles[i].anchorOffsetY = this._titles[i].height / 2
            this.addChildAt(this._titles[i], i)
            this._titleWidth = this._titles[i].width
            this._titleHeight = this._titles[i].height
        }
    }

    public LookAt(x: number, y: number): void {
        this._lookX = x
        this._lookY = y
        this.x = App.StageUtils.getWidth() / 2 - this._lookX //- 250
        this.y = App.StageUtils.getHeight() / 2 - this._lookY// - 450

        let indexX = Math.floor(this._lookX / this._titleWidth)
        let indexY = Math.floor(this._lookY / this._titleHeight)
        //console.debug("LookAt(%d, %d)=>(%d, %d)=>((%d, %d)", this._view.x, this._view.y, this._lookX, this._lookY, indexX, indexY)
        //console.debug("(%d, %d)", App.StageUtils.getStage().width, App.StageUtils.getStage().height)
        this._titlePos(0, (indexX) * this._titleWidth, (indexY - 1) * this._titleHeight)
        this._titlePos(1, (indexX) * this._titleWidth, (indexY) * this._titleHeight)
        this._titlePos(2, (indexX) * this._titleWidth, (indexY + 1) * this._titleHeight)
        this._titlePos(3, (indexX) * this._titleWidth, (indexY + 2) * this._titleHeight)

        this._titlePos(4, (indexX - 1) * this._titleWidth, (indexY - 1) * this._titleHeight)
        this._titlePos(5, (indexX - 1) * this._titleWidth, (indexY) * this._titleHeight)
        this._titlePos(6, (indexX - 1) * this._titleWidth, (indexY + 1) * this._titleHeight)
        this._titlePos(7, (indexX - 1) * this._titleWidth, (indexY + 2) * this._titleHeight)

        this._titlePos(8, (indexX + 1) * this._titleWidth, (indexY - 1) * this._titleHeight)
        this._titlePos(9, (indexX + 1) * this._titleWidth, (indexY) * this._titleHeight)
        this._titlePos(10, (indexX + 1) * this._titleWidth, (indexY + 1) * this._titleHeight)
        this._titlePos(11, (indexX + 1) * this._titleWidth, (indexY + 2) * this._titleHeight)

        this._titlePos(12, (indexX + 2) * this._titleWidth, (indexY - 1) * this._titleHeight)
        this._titlePos(13, (indexX + 2) * this._titleWidth, (indexY) * this._titleHeight)
        this._titlePos(14, (indexX + 2) * this._titleWidth, (indexY + 1) * this._titleHeight)
        this._titlePos(15, (indexX + 2) * this._titleWidth, (indexY + 2) * this._titleHeight)
    }

    private _titlePos(i: number, x: number, y: number): void {
        this._titles[i].x = x
        this._titles[i].y = y
        //console.debug("====(%d, %d)", x, y)
    }
}